package group2assignone.view.customer;

import group2assignone.func.UCCtoALAdapter;
import group2assignone.model.Customer;
import group2assignone.ucm.customer.UCCancelGuest;
import group2assignone.ucm.customer.UCCustomerRegister;
import group2assignone.view.OurView;
import java.awt.*;
import javax.swing.*;
import javax.swing.border.EtchedBorder;

/**
 * This GUI allows the customer to edit their account.
 * @author group2
 */
public class CustomerCreateView extends OurView {

    private static final int textSize = 10;//size of text box 
    private JButton createAccount = new JButton("Create Account");
    private JButton cancel = new JButton("Cancel");
    private JTextField userName = new JTextField(textSize);
    private JTextField password = new JTextField(textSize);
    private JTextField fName = new JTextField(textSize);
    private JTextField lName = new JTextField(textSize);
    private JTextField dob = new JTextField(textSize);
    private JLabel userNameLab = new JLabel("User Name: ");
    private JLabel passwordLab = new JLabel("Password: ");
    private JLabel fNameLab = new JLabel("First Name: ");
    private JLabel lNameLab = new JLabel("Last Name: ");
    private JLabel dobLab = new JLabel("Date Of Birth: ");
    private GridLayout grid;
    private Customer customer;
    private int option;
    private JLabel custLab = new JLabel("Welcome Guest");;

    /**
     * Function to add the GUI components to the frame.
     */
    @Override
    public void addComponents() {

        setTitle("Create Account");

        northPanel.setLayout(new BoxLayout(northPanel, BoxLayout.LINE_AXIS));
        custLab.setAlignmentX(JLabel.LEFT);
        northPanel.add(custLab);

        grid = new GridLayout(3, 2, 2, 1);
        westPanel.setLayout(grid);
        eastPanel.setLayout(grid);
        grid.setVgap(20);

        westPanel.add(userNameLab);
        westPanel.add(userName);
        westPanel.add(passwordLab);
        westPanel.add(password);
        westPanel.add(fNameLab);
        westPanel.add(fName);
        eastPanel.add(lNameLab);
        eastPanel.add(lName);
        eastPanel.add(dobLab);
        eastPanel.add(dob);

        southPanel.add(createAccount);
        southPanel.add(cancel);

        eastPanel.setBorder(BorderFactory.createEmptyBorder(20, 10, 20, 20));
        westPanel.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 10));
        northPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
        southPanel.setBorder(BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));

        createAccount.addActionListener(new UCCtoALAdapter(new UCCustomerRegister(this)));
        cancel.addActionListener(new UCCtoALAdapter(new UCCancelGuest(this)));
    }

    /**
     * Displays a confirm option to the user
     *
     * @return int option - returns int depending on JOptionPane.YES_NO_OPTION
     */
    public int confirmCreate() {

        option = JOptionPane.showConfirmDialog(
                this,
                "Are you sure you want to create the account?",
                "Confirm",
                JOptionPane.YES_NO_OPTION);
        return option;
    }

    /**
     * loads the text fields into the corresponding
     * customer fields for the 'new customer'
     * @param newCust
     */
    public void upLoad(Customer newCust) {
        newCust.setUsername(userName.getText());
        newCust.setPassword(password.getText());
        newCust.setDob(dob.getText());
        newCust.setFName(fName.getText());
        newCust.setLName(lName.getText());
    }

    /**
     * notifies user their account has successfully been edited.
     */
    public void notifyCreate() {
        JOptionPane.showMessageDialog(this,
                "Your account was successfully created");
    }
}


